import { dictionaryByName, dictionaryByPriority } from "$api/dictionary"
import { tasksSave } from "$api/tasks"
import { colors, imgs } from "$utils/imgs"

export default {
  data() {
    return {
      colors: colors,
      icons: imgs,
      addForm: {
        editable: true,
        form: {
          taskDate: "",
          taskName: "",
          priority: 2,
          planTime: "",
          taskType: "默认类型",
          selctColor: "#F9E3DD",
          selectBg: "a7"
        }
      },
      taskTypeOp: [],
      priorityOp: []
    }
  },
  methods: {
    async getOptions() {
      this.taskTypeOp = await dictionaryByName({
        dicName: "taskType",
        status: 0
      }) || []

      this.taskTypeOp.forEach(item => {
        item.text = item.dicValue
        item.value = item.dicValue
      })

      this.priorityOp = await dictionaryByPriority()
    },
    async save() {
      const { selctColor, selectBg, priority } = this.addForm.form || {}
      const remark = {
        selctColor, selectBg
      }
      const params = {
        ...this.addForm.form,
        remark: JSON.stringify(remark),
        priority: priority + ""
      }
      await tasksSave(params)
      this.appMessage("操作成功", 0)
      setTimeout(() => {
        uni.navigateBack()
      }, 500)
    },
  }
}
